<template>
  <el-aside width="200px">
    <el-menu
      class="el-menu-vertical-demo"
      background-color="#545c64"
      text-color="#fff"
      :collapse-transition = "false">
      <h3>後臺管理系統</h3>
      <el-menu-item
        :index="item.path"
        :key="item.path"
        v-for="item in noChildren()"
        @click="clickMenu(item)">
        <component class="icons" :is="item.icon"></component>
        <span>{{ item.label }}</span>
      </el-menu-item>
      <el-sub-menu
        :index="item.path"
        :key="item.path"
        v-for="item in hasChildren()">
        <template #title>
          <component class="icons" :is="item.icon"></component>
          <span>{{ item.label }}</span>
        </template>
        <!-- <el-menu-item-group>
          <el-menu-item
            v-if="item.children"
            :index="subItem.path"
            v-for="(subItem, subIndex) in item.children"
            :key="subIndex"
            @click="clickMenu(subItem)">
            <component class="icons" :is="subItem.icon"></component>
            <span>{{ subItem.label }}</span>
          </el-menu-item>
        </el-menu-item-group> -->
      </el-sub-menu>
    </el-menu>
  </el-aside>
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router'

const list = [
  {
    path: '/home',
    name: 'home',
    label: '首頁',
    icon: 'HomeFilled',
    url: '/',
    children: null
  }, 
  {
    path: '/user',
    name: 'user',
    label: '用戶管理',
    icon: 'user',
    url: '/user',
    children: null
  },
  {
    path: '/vite-js',
    name: 'app1',
    label: 'app1微應用(vite-js)',
    icon: 'vite',
    url: '/vite-js',
    children: null
  },
  {
    path: '/vite-ts',
    name: 'app2',
    label: 'app2微應用(vite-ts)',
    icon: 'vite',
    url: '/vite-ts',
    children: null
  },
  {
    path: '/vue-js',
    name: 'app3',
    label: 'app3微應用(vue-js)',
    icon: 'vue',
    url: '/vue-js',
    children: null
  }
  // {
  //   path: '/module/app1/save',
  //   name: 'app1_save',
  //   label: 'app1微應用Save',
  //   icon: 'user',
  //   url: '/module/app1/save'
  // },
  // {
  //   path: '/module/app2',
  //   name: 'app2',
  //   label: 'app2微應用',
  //   icon: 'user',
  //   url: '/module/app2'
  // },
  // {
  //   label: '貨品',
  //   icon: 'Setting',
  //   children: [
  //     {
  //       path: '/other',
  //       name: 'other',
  //       label: '其他',
  //       icon: 'location',
  //       url: '/other'
  //     }
  //   ]
  // }
]

const noChildren = () => {
  return list.filter((item) => !item.children)
}

const hasChildren = () => {
  return list.filter((item) => item.children)
}

//const store = useStore()
const router = useRouter()
const clickMenu = (item:any) => {
  router.push({
    path: item.path
  })
}
</script>

<style lang="less" scoped>
.icons {
  width: 18px;
  height: 18px;
  margin-right: 2px;
}

.el-menu {
  border-right: none;
  h3{
    line-height: 48px;
    color: #fff;
    text-align: center;
  }
}

</style>
